<template>
  <el-dialog
    title="交易流水记录"
    :visible.sync="visible"
    width="78%"
    append-to-body
  >
    <avue-crud
      ref="crud"
      :page.sync="page"
      :data="tableData"
      :table-loading="tableLoading"
      :option="tradeFlowOption"
      @on-load="getList"
      @search-change="searchChange"
      @search-reset="searchReset"
    ></avue-crud>
  </el-dialog>
</template>
<script>
import crudMixins from '@/mixins/crud';
import { tradeFlowOption } from '@/const/crud/pet/cloudAdoptOrder.js';
import { fetchAdoptTradeFlowList } from '@/api/core/adopt';
export default {
  name: 'tradeFlowDialog',
  mixins: [crudMixins],
  props: {
    value: {
      type: Boolean,
      default: false,
    },
    orderCode: {
      type: String,
    },
  },
  data() {
    return {
      tradeFlowOption,
    };
  },
  computed: {
    visible: {
      get() {
        return this.value;
      },
      set(val) {
        this.$emit('input', val);
      },
    },
  },
  watch: {
    visible(val) {
      if (val) {
        this.getList();
      }
    },
  },
  methods: {
    getList(page, refresh) {
      if (refresh) {
        this.page.current = 1;
        this.page.currentPage = 1;
      }
      this.tableLoading = true;
      fetchAdoptTradeFlowList(
        this.orderCode,
        Object.assign(
          {
            current: this.page.currentPage,
            size: this.page.pageSize,
          },
          this.searchForm
        )
      )
        .then((res) => {
          this.tableData = res.data.data.records;
          this.page.total = res.data.data.total;
          this.tableLoading = false;
        })
        .catch(() => {
          this.tableLoading = false;
        });
    },
  },
};
</script>
